<?php


namespace app\xiangji\controller;


use app\Request;
use app\xiangji\BaseController;
use app\xiangji\services\UserRechargeService;
use app\xiangji\services\WechatService;
use think\App;

class Wechat extends BaseController
{
    private $wechatService;
    private $rechargeService;

    public function __construct(WechatService $service, UserRechargeService $rechargeService)
    {
        $this->wechatService = $service;
        $this->rechargeService = $rechargeService;
    }

    /**
     * @todo 发送手机短信
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\Exception
     */
    public function decryptPhone(Request $request)
    {
        $code = $request->post('code');
        $iv = $request->post('iv');
        $encryptedData = $request->post('encryptedData');
        $result = $this->wechatService->decryptUserPhone($code, $iv, $encryptedData);
        return $this->success($result);
    }

    /**
     * @todo 生成小程序码
     * @param  width 小程序码宽度
     * @param  path 小程序码扫码进入页
     * @return \think\response\Json
     */
    public function generateShareQRCode(Request $request)
    {
        $path = $request->get('path', 'pages/Home/home');
        $data = $request->get('data', null);
        $width = $request->get('width', 430);
        $result = $this->wechatService->generateShareQRCode($path, $data, $width);
        return $this->success($result);
    }
}
